package com.hqyj.springBoot.modules.common.controller;

import com.hqyj.springBoot.modules.common.entity.Mail;
import com.hqyj.springBoot.modules.common.entity.ResultEntity;
import com.hqyj.springBoot.modules.common.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yun
 * @date 2021-5-8 10:19
 */
@RestController
@RequestMapping("api")
public class MailController {
    @Autowired
    private MailService mailService;

    /**
     * - 简单邮件
     * 127.0.0.1/api/simpleMail ---- post
     * {"to":["873396574@qq.com"],"cc":["by873396574@vip.qq.com"],"subject":"简单邮件的标题",
     * "text":"简单邮件的内容"}
     */
    @PostMapping(value = "/simpleMail",consumes = "application/json")
    public ResultEntity<Object> sendSimpleMail(@RequestBody Mail mail) {
        return mailService.sendSimpleMail(mail);
    }

    /**
     * - 富文本邮件
     * 127.0.0.1/api/complexMail ---- post
     * {"to":["873396574@qq.com"],"cc":["by873396574@vip.qq.com"],"subject":"复杂邮件的标题",
     * "text":"<html><head></head><body><h1>hello! Welcome Hyman!</h1><br><img src='cid:image-0'>
     * </img><br><img src='cid:image-1'></img></body></html>","attachments":["F:/JavaYDM/biji.txt"],
     * "images":["F:/JavaYDM/111.jpg","F:/JavaYDM/222.jpg"]}
     */
    @PostMapping(value = "/complexMail",consumes = "application/json")
    public ResultEntity<Object> sendComplexMail(@RequestBody Mail mail) {
        return mailService.sendComplexMail(mail);
    }

    /**
     * - Thymeleaf 模版邮件
     * 127.0.0.1/api/templateMail/welcome ---- post
     * {"to":["873396574@qq.com"],"cc":["by873396574@vip.qq.com"],"subject":"模板邮件的标题",
     * "text":"模板邮件的内容","templateMap":{"name":"baiyun","id":"12345"},"templateId":"welcome"}
     */
    @PostMapping(value = "/templateMail",consumes = "application/json")
    public ResultEntity<Object> sendTemplateMail(@RequestBody Mail mail) {
        return mailService.sendTemplateMail(mail);
    }
}
